home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Misc / emu / p-interp.lha / p-interp-0.5 / Sets.c < prev    next >
C/C++ Source or Header  |  2001-05-20  |  2KB  |  91 lines

  1. /*
  2.  
  3.   P-Code interpreter (to run the apple pascal system)
  4.   Copyright (C) 2000 Mario Klebsch
  5.  
  6.   This program is free software; you can redistribute it and/or modify
  7.   it under the terms of the GNU General Public License as published by
  8.   the Free Software Foundation; either version 2 of the License, or
  9.   (at your option) any later version.
  10.  
  11.   This program is distributed in the hope that it will be useful,
  12.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.   GNU General Public License for more details.
  15.  
  16.   You should have received a copy of the GNU General Public License
  17.   along with this program; if not, write to the Free Software
  18.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.   $Log: Sets.c,v $
  21.   Revision 1.2  2001/05/20 13:12:02  mario
  22.   CVS-Idents und Logs eingefügt
  23.  
  24.  
  25. */
  26.  
  27. #ident "$Id: Sets.c,v 1.2 2001/05/20 13:12:02 mario Exp $";
  28.  
  29. #include "psystem.h"
  30. #include "Sets.h"
  31.  
  32. void SetPop(Set_t *Set)
  33. {
  34.   int    i;
  35.  
  36.   Set->Size=Pop();
  37.   for (i=0;i<Set->Size;i++)
  38.     Set->Data[i]=Pop();
  39. }
  40.  
  41. void SetAdj(Set_t *Set, word Size)
  42. {
  43.   int i;
  44.   for (i=Set->Size; i<Size; i++)
  45.     Set->Data[i]=0;
  46.   Set->Size=Size;
  47. }
  48.  
  49. void SetPush(Set_t *Set)
  50. {
  51.   int i;
  52.   for (i=Set->Size;i;i--)
  53.     Push(Set->Data[i-1]);
  54.   Push(Set->Size);
  55. }
  56.  
  57. /* Set-Compare: return 0 if Set1==Set2, 1 if Set1!=Set2 */
  58.  
  59. int SetCmp(Set_t *Set1, Set_t *Set2)
  60. {
  61.   int    Size= (Set1->Size>Set2->Size) ? Set1->Size : Set2->Size;
  62.   int    i;
  63.  
  64.   if (Set1->Size < Size)
  65.     SetAdj(Set1, Size);
  66.   if (Set2->Size < Size )
  67.     SetAdj(Set2, Size);
  68.  
  69.   for (i=0;i<Size; i++)
  70.     if (Set1->Data[i]!=Set2->Data[i])
  71.       return(1);
  72.   return(0);
  73. }
  74.  
  75. /* returns 1 if SS is subset of S */
  76.  
  77. int SetIsSubset(Set_t *S, Set_t *SS)
  78. {
  79.   int    Size=SS->Size;
  80.   int    i;
  81.  
  82.   if (S->Size < Size)
  83.     SetAdj(S, Size);
  84.  
  85.   for (i=0; i<Size; i++)
  86.     if  ( (S->Data[i]&SS->Data[i]) != SS->Data[i] )
  87.       return(0);
  88.   return(1);
  89. }
  90.  
  91.